1 /* 2 * Copyright (c) 2013 - Mauro Carvalho Chehab <m.chehab@samsung.com> 3 * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Lesser General Public License as published by 7 * the Free Software Foundation version 2.1 of the License. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 18 * 19 */ 20 21 /** 22 * @file vct.h 23 * @ingroup dvb_table 24 * @brief Provides the descriptors for TVCT and CVCT tables 25 * @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1) 26 * @author Mauro Carvalho Chehab 27 * @author Andre Roth 28 * 29 * @par Relevant specs 30 * The table described herein is defined at: 31 * - ATSC A/65:2009 32 * 33 * @see http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/TVCT.aspx 34 * @see http://www.etherguidesystems.com/help/sdos/atsc/syntax/tablesections/CVCT.aspx 35 * 36 * @par Bug Report 37 * Please submit bug reports and patches to linux-media@vger.kernel.org 38 */ 39 40 module libdvbv5_d.vct; 41 42 import core.sys.posix.unistd; 43 44 import libdvbv5_d.descriptors: dvb_desc; 45 import libdvbv5_d.dvb_fe: dvb_v5_fe_parms; 46 import libdvbv5_d.header: dvb_table_header; 47 48 extern (C): 49 50 /* ssize_t */ 51 52 /** 53 * @def ATSC_TABLE_TVCT 54 * @brief TVCT table ID 55 * @ingroup dvb_table 56 * @def ATSC_TABLE_CVCT 57 * @brief CVCT table ID 58 * @ingroup dvb_table 59 * @def ATSC_TABLE_VCT_PID 60 * @brief Program ID with the VCT tables on it 61 * @ingroup dvb_table 62 */ 63 enum ATSC_TABLE_TVCT = 0xc8; 64 enum ATSC_TABLE_CVCT = 0xc9; 65 enum ATSC_TABLE_VCT_PID = 0x1ffb; 66 67 /** 68 * @struct atsc_table_vct_channel 69 * @brief ATSC VCT channel table (covers both CVCT and TVCT) 70 * @ingroup dvb_table 71 * 72 * @param modulation_mode modulation mode 73 * @param minor_channel_number minor channel number 74 * @param major_channel_number major channel number 75 * @param carrier_frequency carrier frequency 76 * @param channel_tsid channel tsid 77 * @param program_number program number 78 * @param service_type service type 79 * @param hide_guide hide guide 80 * @param out_of_band out of band (CVCT only) 81 * @param path_select path select (CVCT only) 82 * @param hidden hidden 83 * @param access_controlled access controlled 84 * @param ETM_location ETM location 85 * @param source_id source ID 86 * @param descriptors_length length of the descriptors 87 * 88 * @param descriptor pointer to struct dvb_desc 89 * @param next pointer to another struct atsc_table_vct_channel 90 * @param descriptors_length length of the descriptors 91 * @param short_name short name. The __short_name is converted 92 * from UTF-16 to locale charset when parsed 93 * 94 * This structure is used to store the original VCT channel table, 95 * converting the integer fields to the CPU endianness. 96 * 97 * The undocumented parameters are used only internally by the API and/or 98 * are fields that are reserved. They shouldn't be used, as they may change 99 * on future API releases. 100 * 101 * Everything after atsc_table_vct_channel::descriptor (including it) won't 102 * be bit-mapped * to the data parsed from the MPEG TS. So, metadata are 103 * added there. 104 */ 105 struct atsc_table_vct_channel 106 { 107 align (1): 108 109 ushort[7] __short_name; 110 111 union 112 { 113 align (1): 114 115 uint bitfield1; 116 117 struct 118 { 119 import std.bitmanip : bitfields; 120 align (1): 121 122 mixin(bitfields!( 123 uint, "modulation_mode", 8, 124 uint, "minor_channel_number", 10, 125 uint, "major_channel_number", 10, 126 uint, "reserved1", 4)); 127 } 128 } 129 130 uint carrier_frequency; 131 ushort channel_tsid; 132 ushort program_number; 133 134 union 135 { 136 align (1): 137 138 ushort bitfield2; 139 140 struct 141 { 142 import std.bitmanip : bitfields; 143 align (1): 144 145 mixin(bitfields!( 146 ushort, "service_type", 6, 147 ushort, "reserved2", 3, 148 ushort, "hide_guide", 1, 149 ushort, "out_of_band", 1, 150 ushort, "path_select", 1, 151 ushort, "hidden", 1, 152 ushort, "access_controlled", 1, 153 ushort, "ETM_location", 2)); 154 155 /* CVCT only */ 156 /* CVCT only */ 157 } 158 } 159 160 ushort source_id; 161 162 union 163 { 164 align (1): 165 166 ushort bitfield3; 167 168 struct 169 { 170 import std.bitmanip : bitfields; 171 align (1): 172 173 mixin(bitfields!( 174 ushort, "descriptors_length", 10, 175 ushort, "reserved3", 6)); 176 } 177 } 178 179 /* 180 * Everything after atsc_table_vct_channel::descriptor (including it) 181 * won't be bit-mapped to the data parsed from the MPEG TS. So, 182 * metadata are added there 183 */ 184 // struct dvb_desc; 185 dvb_desc* descriptor; 186 atsc_table_vct_channel* next; 187 188 /* The channel_short_name is converted to locale charset by vct.c */ 189 190 char[32] short_name; 191 } 192 193 /** 194 * @struct atsc_table_vct 195 * @brief ATSC VCT table (covers both CVCT and TVCT) 196 * @ingroup dvb_table 197 * 198 * @param header struct dvb_table_header content 199 * @param protocol_version protocol version 200 * @param num_channels_in_section num channels in section 201 * @param channel pointer to struct channel 202 * @param descriptor pointer to struct descriptor 203 * 204 * Everything after atsc_table_vct::channel (including it) won't be bit-mapped 205 * to the data parsed from the MPEG TS. So, metadata are added there 206 */ 207 struct atsc_table_vct 208 { 209 align (1): 210 211 dvb_table_header header; 212 ubyte protocol_version; 213 214 ubyte num_channels_in_section; 215 216 atsc_table_vct_channel* channel; 217 dvb_desc* descriptor; 218 } 219 220 /** 221 * @union atsc_table_vct_descriptor_length 222 * @brief ATSC VCT descriptor length 223 * @ingroup dvb_table 224 * 225 * @param descriptor_length descriptor length 226 * 227 * Used internally by the library to parse the descriptor length endianness. 228 */ 229 union atsc_table_vct_descriptor_length 230 { 231 align (1): 232 233 ushort bitfield; 234 235 struct 236 { 237 import std.bitmanip : bitfields; 238 align (1): 239 240 mixin(bitfields!( 241 ushort, "descriptor_length", 10, 242 ushort, "reserved", 6)); 243 } 244 } 245 246 /** 247 * @brief Macro used to find channels on a VCT table 248 * @ingroup dvb_table 249 * 250 * @param _channel channel to seek 251 * @param _vct pointer to struct atsc_table_vct_channel 252 */ 253 254 // struct dvb_v5_fe_parms; 255 256 /** 257 * @brief Initializes and parses VCT table 258 * @ingroup dvb_table 259 * 260 * @param parms struct dvb_v5_fe_parms pointer to the opened device 261 * @param buf buffer containing the VCT raw data 262 * @param buflen length of the buffer 263 * @param table pointer to struct atsc_table_vct to be allocated and filled 264 * 265 * This function allocates an ATSC VCT table and fills the fields inside 266 * the struct. It also makes sure that all fields will follow the CPU 267 * endianness. Due to that, the content of the buffer may change. 268 * 269 * @return On success, it returns the size of the allocated struct. 270 * A negative value indicates an error. 271 */ 272 ssize_t atsc_table_vct_init ( 273 dvb_v5_fe_parms* parms, 274 const(ubyte)* buf, 275 ssize_t buflen, 276 atsc_table_vct** table); 277 /** 278 * @brief Frees all data allocated by the VCT table parser 279 * @ingroup dvb_table 280 * 281 * @param table pointer to struct atsc_table_vct to be freed 282 */ 283 void atsc_table_vct_free (atsc_table_vct* table); 284 /** 285 * @brief Prints the content of the VCT table 286 * @ingroup dvb_table 287 * 288 * @param parms struct dvb_v5_fe_parms pointer to the opened device 289 * @param table pointer to struct atsc_table_vct 290 */ 291 void atsc_table_vct_print (dvb_v5_fe_parms* parms, atsc_table_vct* table);